import 'package:kxy_flutter_app/model/course_resource.dart';

enum CourseStatus {
  NotStarted,
  Learning,
  Completed,
}

class Course {
  String id;
  String title;
  String brief;
  String imgUrl;
  CourseStatus status;
  int viewCount;
  int finishRate;
  DateTime updateTime;
  List<CourseResource> resourceList;

  Course({
    this.id,
    this.title,
    this.brief,
    this.imgUrl,
    this.status,
    this.viewCount,
    this.finishRate,
    this.updateTime,
    this.resourceList,
  });

  factory Course.fromJson(Map<String, dynamic> json) {
    return Course(
      id: json['id'],
      title: json['title'],
      brief: json['brief'],
      imgUrl: json['imgUrl'],
      status: CourseStatus.values[json['classStatus']],
      viewCount: json['viewCount'],
      finishRate: json['finishRate'],
      updateTime: json['updateTime'] == null ? null : DateTime.parse(json['updateTime']),
      resourceList: (json['resourse'] as List).map((e) => CourseResource.fromJson(e)).toList(),
    );
  }
}

class CourseProfile {
  String id;
  String title;
  String imgUrl;
  int viewCount;
  CourseStatus status;
  DateTime publishDate;

  CourseProfile({this.id, this.title, this.imgUrl, this.status, this.viewCount, this.publishDate});

  factory CourseProfile.fromJson(Map<String, dynamic> json) {
    return CourseProfile(
      id: json['id'],
      title: json['title'],
      imgUrl: json['imgUrl'],
      status: CourseStatus.values[json['classStatus']],
      viewCount: json['viewCount'],
      publishDate: json['createTime'] == null ? null : DateTime.parse(json['createTime']),
    );
  }
}
